<template>
    <div>
        <a-modal
            v-model:visible="visible"
            :title="row.realname+'--单位推荐表'"
            @cancel="visible = false"
            width="100%"
            wrapClassName="recommend-full-modal"
            :footer="null"
        >
            <div  style="margin-bottom: 10px;">
                <a-button v-if="view == '0'|| view == '3'" style="margin-right: 10px;" type="primary" icon="check-circle" @click="auditPassThrough()" ghost>审核通过</a-button>
                <a-button v-if="view == '0'|| view == '2'" style="margin-right: 10px;" icon="stop" @click="auditNOPASS()" type="danger" ghost>审核不通过</a-button>
                <a-button type="primary" icon="download" ghost @click="downloadClick()">下载</a-button>
            </div>
            <div>
                <div style="position: relative;">
                    <div style="position: absolute;left: 50%;top: 10px;z-index: -1;">
                        <a-spin tip="正在加载中..."></a-spin>
                    </div>
                    <iframe 
                        :key="iframeDataKey"
                        v-if="iframeSrc"
                        :src="iframeSrc" 
                        ref="iframeServerEditingRef" 
                        scrolling="auto" 
                        width="100%" 
                        :height="(windowInnerHeight - 120 )+'px'"
                        style="border: 0;"
                    ></iframe>
                    <span v-else>当前文件发生错误！</span>
                </div>
            </div>
            <howeverReason ref="howeverReasonRef" @auditNOPASS="auditNOPASS"/>
        </a-modal>
    </div>
</template>
<script>
import YchConstant from '@/api/YchConstant'
import blobType from '@/common/blobType'
import howeverReason from './howeverReason.vue'
import {
    jcylxjhupdateLxUserShtg,
    jcylxjhupdateLxUserShbtg,
    jcylxdjcjdownloadDjbFile,
} from './service/index'
export default {
    components:{
        howeverReason,
    },
    props:{

    },
    data(){
        return{
            visible:false,
            windowInnerHeight:window.innerHeight,
            iframeDataKey:null,
            iframeSrc:'',
            row:{},
            view:false,
        }
    },
    watch:{

    },
    mounted(){
        
    },
    methods:{
        getData(row,view){
            this.view = view
            this.row = row
            this.iframeDataKey = Date.now()
            this.iframeSrc = bootConfig[process.env.NODE_ENV].locality_ApI + YchConstant.SPZX_SPCY + '/jcylxdjcj/downloadDjbFile?id='+row.id
        },
        auditPassThrough(){
            var that = this
            this.$confirm({
                title:'您确认要审核通过吗？',
                // icon: createVNode(ExclamationCircleOutlined),
                onOk() {
                    jcylxjhupdateLxUserShtg({ids:that.row.id}).then(res=>{
                        if(res.code == 200){
                            that.view = true
                            that.$message.success(res.message)
                            that.$emit('refreshTable1Change')
                        }else{
                            that.$message.warning(res.message)
                        }
                    })
                }
            })
        },
        txyyauditModel(){
            this.$refs.howeverReasonRef.getData({ids:this.row.id})
            this.$refs.howeverReasonRef.visible = true
        },
        auditNOPASS(row){//审核不通过
            var that = this
            jcylxjhupdateLxUserShbtg(row).then(res=>{
                if(res.code == 200){
                    that.$refs.howeverReasonRef.visible = false
                    that.$message.success(res.message)
                    that.refreshTable1 = Date.now()
                    that.getExamineInfoNum()
                }else{
                    that.$message.warning(res.message)
                }
            })
            
        },
        auditNOPASS(){
            var that = this
            this.$confirm({
                title:'您确认要审核不通过吗？',
                // icon: createVNode(ExclamationCircleOutlined),
                onOk() {
                    jcylxjhupdateLxUserShbtg({ids:that.row.id}).then(res=>{
                        if(res.code == 200){
                            that.view = true
                            that.$message.success(res.message)
                            that.$emit('refreshTable1Change')
                        }else{
                            that.$message.warning(res.message)
                        }
                    })
                }
            })
        },
        downloadClick(){
            let val = {
                fwjlx:'.pdf',
                fileName:this.row.realname+'单位推荐表'
            }
            jcylxdjcjdownloadDjbFile({id:this.row.id}).then((data) => {
                this.DownloadTemplateLoading = false
                if (!data) {
                    that.$message.warning('文件下载失败')
                    return
                }
                    let index = blobType.suffix.indexOf(val.fwjlx)
                    let url = window.URL.createObjectURL(new Blob([data], { type:blobType.type[index] }))
                    let link = document.createElement('a')
                    link.style.display = 'none'
                    link.href = url
                    link.setAttribute('download', val.fileName + val.fwjlx)
                    document.body.appendChild(link)
                    link.click()
                    document.body.removeChild(link) //下载完成移除元素
                    window.URL.revokeObjectURL(url) //释放掉blob对象
                // }
            })
        },
    }
}
</script>
<style lang="less">
.recommend-full-modal {
  .ant-modal {
    max-width: 100%;
    top: 0;
    padding-bottom: 0;
    margin: 0;
  }
  .ant-modal-content {
    display: flex;
    flex-direction: column;
    height: calc(100vh);
  }
  .ant-modal-body {
    flex: 1;
    padding: 12px;
  }
}
</style>